import {Injectable} from '@angular/core';
import * as comutils from 'comutils';
import {LoadingController} from '@ionic/angular';
import {OverlayBaseController} from '@ionic/angular/dist/util/overlay';

@Injectable({
    providedIn: 'root'
})
export class CommonService {

    loadObject = null;

    constructor(private loadingController: LoadingController) {
    }

    checkUserSession(userInfo: object): Promise<boolean> {
        return Promise.resolve(userInfo != null);
    }

    loading(message?, duration = 2000) {
        this.loadingController.create({
            message: message,
            duration: duration
        }).then(value => {
            this.loadObject = value;
            this.loadObject.present();
        });
    }

    hideloading() {
        if (this.loadObject) {
            this.loadObject.dismiss();
        }
    }
}
